const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            photo,
            page: {
                activeName: 'first',
                value1: '',
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%")))
            },
            form:{},
            showDialog1:false,
            project_examine_log_attachment:[],
            str1: '',
            str: '',
        }
    },
    mounted() {

    },
    methods: {
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%")));
            this.postgetList(this.page);
        },
        handleClick() {
            if (this.page.activeName == 'first') {
                this.str1 = '';
            } else if (this.page.activeName == 'second') {
                this.str1 = "\r\nAND project.Project_Status = '1'\r\n";
            } else if (this.page.activeName == 'third') {
                this.str1 = "\r\nAND project.Project_Status = '2'\r\n";
            } else if (this.page.activeName == 'fourth') {
                this.str1 = "\r\nAND project.Project_Status = '3'\r\n";
            } else if (this.page.activeName == 'fifth') {
                this.str1 = "\r\nAND project.Project_Status = '4'\r\n";
            } else if (this.page.activeName == 'sixth') {
                this.str1 = "\r\nAND project.Project_Status = '5'\r\n";
            }
            this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str + this.str1)));
            this.postgetList(this.page)
        },
        //树的点击筛选事件
        handleNodeClick(data, node) {
            this.str = "AND project.Project_Implementation_Subject='"+data.Government_Agencies_SerialNumber +"'\r\n"
            this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str + this.str1)));;
            this.postgetList(this.page);
        },
        examine(row) {
            let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
            window.location.href = "./examine.html?action=Modify&nodeKey=" + row[primary_key];
        },
        examine1(row, is) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'project',
                    Condition: `Project_SerialNumber='${row.Project_SerialNumber}'`,
                },
                success: (project) => {
                    if (is == '5') {
                        this.$confirm('此操作后该项目将会竣工,是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                        }).then(() => {
                            project[0].Project_Status = is;
                            let lJSONObject_DataSet = {
                                Modify: {
                                    project
                                },
                                Add: {
                                    project_examine_log: [{
                                        Project_SerialNumber: row.Project_SerialNumber,
                                        Row_Status: '3'
                                    }]
                                }
                            }
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSaveByRequestBody",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet, (res) => {
                                if (res.Status == 'success') {
                                    this.postgetList(this.page)
                                }
                                this.loading = false;
                            })
                            // $.ajax({
                            //     headers: requestHeaders("JSON"),
                            //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                            //     method: "post",
                            //     data: JSON.stringify({
                            //         Data: lJSONObject_DataSet,
                            //     }),
                            //     success: (res) => {
                            //         if (res.Status == 'success') {
                            //             this.postgetList(this.page)
                            //         }
                            //     },
                            //     complete: (XMLHttpRequest) => {
                            //         this.loading = false;
                            //         requestPretreatment(XMLHttpRequest)
                            //     }
                            // });
                        }).catch(() => { });
                    } else if (is == '7') {
                        this.$prompt("请输入拒绝原因", '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                            inputPattern: /^\s*\S.+$/,
                            inputErrorMessage: "请输入拒绝原因"
                        }).then(({ value }) => {
                            project[0].Project_Status = is;
                            let lJSONObject_DataSet = {
                                Modify: {
                                    project
                                },
                                Add: {
                                    project_examine_log: [{
                                        Project_SerialNumber:  row.Project_SerialNumber,
                                        Reason: value,
                                        Row_Status: '4'
                                    }]
                                }
                            }
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSaveByRequestBody",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet, (res) => {
                                if (res.Status == 'success') {
                                    this.postgetList(this.page)
                                }
                                this.loading = false;
                            })
                            // $.ajax({
                            //     headers: requestHeaders("JSON"),
                            //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                            //     method: "post",
                            //     data: JSON.stringify({
                            //         Data: lJSONObject_DataSet,
                            //     }),
                            //     success: (res) => {
                            //         if (res.Status == 'success') {
                            //             this.postgetList(this.page);
                            //         }
                            //     },
                            //     complete: (XMLHttpRequest) => {
                            //         this.loading = false;
                            //         requestPretreatment(XMLHttpRequest)
                            //     }
                            // });
                        }).catch(() => { });
                    }
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                },
            });
        },
        success(row, res) {
            this.project_examine_log_attachment.push({
                uid: row.uid,
                Attachment_URL: res.fileName,
                Attachment_Name:row.name,
                Temp_Path:res.tempPath,
            })
        },
        remove(row) {
            if (!Object.keys(row).some(item => item.includes('_Original'))) {
                this.project_examine_log_attachment = this.project_examine_log_attachment.filter(i => i.uid != row.uid);
            } else {
                let obj = this.project_examine_log_attachment.filter(i => i.Attachment_SerialNumber == row.Attachment_SerialNumber)[0];
                obj.Row_Status = '1'
            }
        },
        handleRework(row){
            this.form = row;
            this.showDialog1 = true;
        },
        handleSubmit(row){
            this.loading = true;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'project',
                    Condition: `Project_SerialNumber='${row.Project_SerialNumber}'`,
                },
                success: (project) => {
                    project[0].Project_Status = '6';
                    let lJSONObject_DataSet = {
                        Modify: {
                            project
                        },
                        Add: {
                            project_examine_log: [{
                                Project_SerialNumber:  row.Project_SerialNumber,
                                Row_Status: '5',
                                Children:{
                                    project_examine_log_attachment:this.project_examine_log_attachment
                                }
                            }]
                        }
                    }
                    let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                    lJSONObject_DataSet['Add']['base_operation_log'] = [{
                        Operation_Type: '0',
                        Operation_Path: this.relativePath,
                        Operation_Main,
                        Operation_Interface: "generalSaveByRequestBody",
                        Operation_IP: getIpAddress()
                    }]
                    submitSave(lJSONObject_DataSet, (res) => {
                        if (res.Status == 'success') {
                            this.showDialog1 = false;
                            this.postgetList(this.page);
                        }
                        this.loading = false;
                    })
                    // $.ajax({
                    //     headers: requestHeaders("JSON"),
                    //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                    //     method: "post",
                    //     data: JSON.stringify({
                    //         Data: lJSONObject_DataSet,
                    //     }),
                    //     success: (res) => {
                    //         if (res.Status == 'success') {
                    //             this.showDialog1 = false;
                    //             this.postgetList(this.page);
                    //         }
                    //         this.loading = false;
                    //     },
                    //     complete: (XMLHttpRequest) => {
                    //         requestPretreatment(XMLHttpRequest)
                    //     }
                    // });
                },
                complete: (XMLHttpRequest) => {
                    this.loading = false;
                    requestPretreatment(XMLHttpRequest)
                }
            })
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
